package araxy.blog.interceptor.exceptionhandler;

import araxy.blog.exception.BlogException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@ControllerAdvice
public class MyExceptionHandler {

    Logger logger = LoggerFactory.getLogger(MyExceptionHandler.class);

    private Map<String,Object> getErrMsgMap(BlogException e) {
        Map<String,Object> map = new HashMap<>();
        map.put("flg",false);
        map.put("msg",e.getMessage());
        return map;
    }

    @ExceptionHandler(BlogException.class)
    @ResponseBody
    public Map<String,Object> myExceptionHandler(BlogException e) {
        return getErrMsgMap(e);
    }


}